package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// MaterialThemeConfig 素材主题配置
type MaterialThemeConfig struct {
	ID         string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键id"`
	MerchantID string `json:"merchant_id" gorm:"column:merchant_id;type:int;size:64;index:merchant_id;default:0;comment:所属商户"`
	ThemeID    string `json:"theme_id" gorm:"column:theme_id;type:int;size:64;index:theme_id;default:0;comment:主题id"`
	Condition  int    `json:"condition" gorm:"column:condition;type:int;size:64;comment:触发条件"`
	Voice      string `json:"voice" gorm:"column:voice;type:text;not null;comment:关联语音"`
	Emoji      string `json:"emoji" gorm:"column:emoji;type:text;not null;comment:关联表情"`
	Light      string `json:"light" gorm:"column:light;type:text;not null;comment:关联灯光"`
	CreatedAt  int64  `json:"-" gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间"`
	UpdatedAt  int64  `json:"-" gorm:"column:updated_at;autoUpdateTime;type:int;size:64;comment:更新时间"`
}

// TableName 表名
func (MaterialThemeConfig) TableName() string {
	return "material_theme_config_v2"
}

// BeforeCreate 自增id
func (l *MaterialThemeConfig) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID != "" {
		return nil
	}
	// id为空时，自动添加id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	l.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &MaterialThemeConfig{})
}
